from selenium.webdriver.support.ui import WebDriverWait
import traceback
class Base():
    # 封装初始化方法
    def __init__(self,driver):
        self.driver=driver
    # 封装地址方法
    def open_url(self,url):
        self.driver.get(url)

    # 封装隐式等待的方法
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver:driver.find_element(*loc).is_displayed())
            return self.driver.find_element(*loc)
        except Exception as e:
            print(e)
            print(traceback.format_exc())
    # 封装点击方法
    def click(self,loc):
        self.find_element(loc).click()
    # 封装输入方法
    def send_keys(self,loc,text):
        self.find_element(loc).send_keys(text)
    # 封装断言方法
    def dy(self,loc):
        return self.find_element(loc).text